package com.gqyin.demo.domain;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author guiqing.yin
 * 2024-03-28 14:17
 */
@Data
@Accessors(chain = true)
@Document(collection = "user")
public class User implements Serializable {

    @Id
    private String id;

    @NotBlank(message = "'name' must not be blank")
    @Size(min = 3, max = 16, message = "The length of 'name' must be between 3 and 16 characters")
    @Indexed(unique = true)
    @TextIndexed
    private String name;

    @Pattern(regexp = "^1[3-9][0-9]{9}$", message = "Invalid mobile phone number")
    @TextIndexed
    private String phoneNumber;

    @Email(message = "Invalid email address")
    @TextIndexed
    private String email;

    private Map<String, Object> attrs;

    @CreatedDate
    private LocalDateTime createdTime;

    @LastModifiedDate
    private LocalDateTime updatedTime;
}
